//
//  CustomerUIViewController.m
//  UI03_UIViewController
//
//  Created by aaaaaa on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomerUIViewController.h"
#import "SecondViewController.h"

@interface CustomerUIViewController ()

@end

@implementation CustomerUIViewController

//通常重写下面的初始化方法
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    }
    
    return self;
}

//加载视图
-(void)loadView{
    //必须调用父类方法
    [super loadView];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

//视图加载完成，在这个方法中创建子视图和处理数据
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    
    [self createButton];
}

- (void)createButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor redColor];
    button.frame = CGRectMake(100, 100, 80, 30);
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

//button的点击方法
- (void)nextAction:(UIButton *)button{
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    
    //使用模态方式展示其他视图控制器的主视图
    [self presentViewController:secondVC animated:YES completion:^{
      //在secondVC展示主视图后调用
        NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    }];
    
    [secondVC release];
    
}

//视图将要显示在屏幕上
- (void)viewWillAppear:(BOOL)animated{
    //调用父类方法
    [super viewWillAppear:animated];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

//视图已经显示在屏幕上
- (void)viewDidAppear:(BOOL)animated{
    //调用父类方法
    [super viewDidAppear:animated];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

//视图将要在屏幕上消失
- (void)viewWillDisappear:(BOOL)animated{
    //调用父类方法
    [super viewWillDisappear:animated];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

//视图已经从屏幕上消失
- (void)viewDidDisappear:(BOOL)animated{
    //调用父类方法
    [super viewDidDisappear:animated];
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
